#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5+10;

int a,b;
char s[MAXN];

int main (){
	int T; scanf("%d",&T);
	while(T--){
		scanf("%d %d",&a,&b);
		scanf("%s",s+1);
		int ans = 0;bool f = 0;int n = strlen(s+1);
		for(int i = 1,now = 0;i <= n;i++){
			if(s[i] != s[i-1]){
				if(s[i] == '1') ans += f ? min(now * b,a):a,f = 1;
				now = 1;
			}else now++;
		}
		printf("%d\n",ans);
	}
	return 0;
}
